#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author  : YuLei Lan
# @Software: PyCharm

from django_filters import rest_framework as filters
from .user.models import UserInfo
from .models import Roles, Menus


class UserInfoFilter(filters.FilterSet):
    # 根据名字过滤忽略大小写
    user_id = filters.NumberFilter(field_name='id')

    username = filters.CharFilter(field_name='username', lookup_expr='icontains')
    email = filters.CharFilter(field_name='email', lookup_expr='icontains')

    class Meta:
        model = UserInfo
        fields = ('user_id',)
        search_fields = ('username', 'email')


class RolesFilter(filters.FilterSet):
    name = filters.CharFilter(field_name='name', lookup_expr='icontains')
    is_admin = filters.BooleanFilter(field_name='is_admin')

    class Meta:
        model = Roles
        fields = ('is_admin',)
        search_fields = ('name',)


class MenusFilter(filters.FilterSet):
    name = filters.CharFilter(field_name='name', lookup_expr='icontains')

    class Meta:
        model = Menus
        fields = ()
        search_fields = ('name',)
